import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';

import { Hero } from './hero';
import { HeroService } from './hero.service';

@Component({
	moduleId: module.id+'',
	selector: 'my-heroes',
	templateUrl: 'heroes.component.html',
	styleUrls: ['heroes.component.css']
})

export class HeroesComponent implements OnInit {

	title = '英雄';
	heroes: Hero[];
	selectedHero: Hero;

	ngOnInit(): void {
		this.getHeroes();
	}

	constructor(private heroService: HeroService, private router: Router) {
	}

	onSelect(hero: Hero): void {
		this.selectedHero = hero;
	};
	/*初使化*/
	getHeroes(): void {
		// this.heroes = this.heroService.getHeroes();
		//this.heroService.getHeroesSlowly().then(heroes => this.heroes = heroes);
		 // this.heroService.getHeroesByPromise().then(heroes => this.heroes = heroes);
		this.heroService.getHeroesByHttp().then(heroes => this.heroes = heroes);
	}
	gotoDetail(): void {
		this.router.navigate(['/detail', this.selectedHero.id]);
	}
}
